unit uPrintTicket;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Oracle, uutils, gnugettext, umainutils;

type
  TFrmPrintTicket = class(TForm)
    lbl_Player: TLabel;
    img_Logo: TImage;
    Label1: TLabel;
    lbl_TicketType: TLabel;
    lbl_TournamentName: TLabel;
    lbl_TournamentDate: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    lbl_PlayerName: TLabel;
    lbl_Value: TLabel;
    lbl_Fee: TLabel;
    lbl_TotalValue: TLabel;
    lbl_DateTime: TLabel;
    lbl_DateTimeValue: TLabel;
    Label4: TLabel;
    lbl_Table: TLabel;
    OracleQuery1: TOracleQuery;
    tmr_CloseForm: TTimer;
    Label5: TLabel;
    lbl_Seat: TLabel;
    lbl_Dealer: TLabel;
    lbl_DealerValue: TLabel;
    procedure tmr_CloseFormTimer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure SetData(IsCashGame: boolean; TicketID: string; TicketType: string; OraSession: TOracleSession);
    procedure PrintTicket();
  end;

var
  FrmPrintTicket: TFrmPrintTicket;

implementation

uses uFrmMain;
{$R *.dfm}
{ TFrmTicket }

procedure TFrmPrintTicket.FormCreate(Sender: TObject);
begin
  gnugettext.TranslateComponent(self);
end;

procedure TFrmPrintTicket.PrintTicket;
begin
  print();
end;

procedure TFrmPrintTicket.SetData(IsCashGame: boolean; TicketID: string; TicketType: string; OraSession: TOracleSession);
var
  GetDealerStr: string;
begin
  GetDealerStr := '(SELECT US.NAME||'' ''||US.SURNAME FROM TABLE_SUBJECT_LOGINS TSS JOIN USERS US ON US.ID=TSS.USER_ID WHERE ROWNUM=1 AND TOU.EVENT_START BETWEEN IN_DATETIME AND OUT_DATETIME)AS DEALER';
  if TicketID <> '-1' then
  begin
    OracleQuery1.Session := OraSession;
    // img_Logo.Picture := uutils.GetImage('select IMAGE, IMAGE_TYPE from SETTINGS where id=1', OraSession);
    img_Logo.Picture := FrmMain.img_LogoSettings.Picture;
    OracleQuery1.Close;
    lbl_Dealer.Visible := false;
    lbl_DealerValue.Visible := false;
    if IsCashGame then
    begin
      if TicketType = TicketTypeBuy then
      begin
        OracleQuery1.SQL.Text :=
          'SELECT PL.NAME||'' ''||PL.SURNAME AS PLAYER_NAME,(SELECT SYSDATE FROM DUAL) AS NOW, TA.NAME AS TABLE_NAME, TI.SEAT_NUM, TOU.NAME AS TOURNAMENT, TI.INPUT_VALUE AS VALUE  FROM CASH_GAME_TICKETS TI'
          + ' JOIN PLAYERS PL ON TI.PLAYER_ID=PL.ID JOIN CASH_GAMES TOU ON TOU.ID=TI.CASH_GAME_ID JOIN TABLES TA ON TA.ID=TI.TABLE_ID WHERE TI.ID=' + TicketID;
        OracleQuery1.Execute;
        lbl_TicketType.Caption := 'CASH GAME ' + TicketTypeBuy;
      end
      else if TicketType = TicketTypeRebuy then
      begin
        lbl_Dealer.Visible := true;
        lbl_DealerValue.Visible := true;
        OracleQuery1.SQL.Text :=
          'SELECT PL.NAME||'' ''||PL.SURNAME AS PLAYER_NAME,(SELECT SYSDATE FROM DUAL) AS NOW, TA.NAME AS TABLE_NAME, TI.SEAT_NUM, TOU.NAME AS TOURNAMENT, TIR.VALUE AS VALUE,' + GetDealerStr +
          ' FROM CASH_GAME_TICKET_REBUYS TIR' +
          ' JOIN CASH_GAME_TICKETS TI ON TI.ID=TIR.CASH_GAME_TICKET_ID JOIN PLAYERS PL ON TI.PLAYER_ID=PL.ID JOIN CASH_GAMES TOU ON TOU.ID=TI.CASH_GAME_ID JOIN TABLES TA ON TA.ID=TI.TABLE_ID WHERE TIR.ID='
          + TicketID;
        OracleQuery1.Execute;
        lbl_TicketType.Caption := 'CASH GAME ' + TicketTypeRebuy;
      end;
    end
    else
    begin
      if TicketType = TicketTypeBuy then
      begin
        OracleQuery1.SQL.Text := 'SELECT PL.NAME||'' ''||PL.SURNAME AS PLAYER_NAME,(SELECT SYSDATE FROM DUAL) AS NOW, TOU.EVENT_START,TA.NAME AS TABLE_NAME,' + GetDealerStr +
          ' , TI.SEAT_NUM, TOU.NAME AS TOURNAMENT, TI.FEE, BUY_IN AS VALUE  FROM TICKETS TI' +
          ' JOIN PLAYERS PL ON TI.PLAYER_ID=PL.ID JOIN TOURNAMENTS TOU ON TOU.ID=TI.TOURNAMENT_ID JOIN TABLES TA ON TA.ID=TI.TABLE_ID WHERE TI.ID=' + TicketID;
        OracleQuery1.Execute;
        lbl_TicketType.Caption := TicketTypeBuy;
      end
      else if TicketType = TicketTypeRebuy then
      begin
        lbl_Dealer.Visible := true;
        lbl_DealerValue.Visible := true;
        OracleQuery1.SQL.Text := 'SELECT PL.NAME||'' ''||PL.SURNAME AS PLAYER_NAME,(SELECT SYSDATE FROM DUAL) AS NOW,' + GetDealerStr +
          ', TOU.EVENT_START,TA.NAME AS TABLE_NAME, TI.SEAT_NUM, TOU.NAME AS TOURNAMENT, NULL AS FEE, TIR.VALUE  FROM TICKET_REBUY TIR' +
          ' JOIN TICKETS TI ON TI.ID=TIR.TICKET_ID JOIN PLAYERS PL ON TI.PLAYER_ID=PL.ID JOIN TOURNAMENTS TOU ON TOU.ID=TI.TOURNAMENT_ID JOIN TABLES TA ON TA.ID=TI.TABLE_ID WHERE TIR.ID=' +
          TicketID;
        OracleQuery1.Execute;
        lbl_TicketType.Caption := TicketTypeRebuy;
      end
      else if TicketType = TicketTypeAddon then
      begin
        lbl_Dealer.Visible := true;
        lbl_DealerValue.Visible := true;
        OracleQuery1.SQL.Text := 'SELECT PL.NAME||'' ''||PL.SURNAME AS PLAYER_NAME,(SELECT SYSDATE FROM DUAL) AS NOW,' + GetDealerStr +
          ',TOU.EVENT_START,TA.NAME AS TABLE_NAME, TI.SEAT_NUM, TOU.NAME AS TOURNAMENT, NULL AS FEE, TIA.VALUE  FROM TICKET_ADDON TIA' +
          ' JOIN TICKETS TI ON TI.ID=TIA.TICKET_ID JOIN PLAYERS PL ON TI.PLAYER_ID=PL.ID JOIN TOURNAMENTS TOU ON TOU.ID=TI.TOURNAMENT_ID JOIN TABLES TA ON TA.ID=TI.TABLE_ID WHERE TIA.ID=' +
          TicketID;
        OracleQuery1.Execute;
        lbl_TicketType.Caption := TicketTypeAddon;
      end;
    end;
    if not OracleQuery1.eof then
    begin
      if (not IsCashGame) and (TicketType <> TicketTypeAddon) then
      begin
        lbl_Fee.Caption := OracleQuery1.Field('FEE');
        lbl_TournamentDate.Caption := OracleQuery1.Field('EVENT_START');
        lbl_TotalValue.Caption := VarToStr(OracleQuery1.Field('VALUE') + OracleQuery1.Field('FEE')) + ' ' + umainutils.Currency_Symbol;
      end
      else
      begin
        lbl_TournamentDate.Visible := false;
        Label2.Visible := false;
        lbl_Fee.Visible := false;
        lbl_TotalValue.Caption := VarToStr(OracleQuery1.Field('VALUE')) + ' ' + umainutils.Currency_Symbol;
      end;
      lbl_PlayerName.Caption := OracleQuery1.Field('PLAYER_NAME');
      lbl_TournamentName.Caption := OracleQuery1.Field('TOURNAMENT');
      lbl_Value.Caption := VarToStr(OracleQuery1.Field('VALUE')) + ' ' + umainutils.Currency_Symbol;
      lbl_DateTimeValue.Caption := OracleQuery1.Field('NOW');
      lbl_Table.Caption := OracleQuery1.Field('TABLE_NAME');
      lbl_Seat.Caption := OracleQuery1.Field('SEAT_NUM');
      if (TicketType = TicketTypeRebuy) or (TicketType = TicketTypeAddon) then
      begin
        lbl_DealerValue.Caption := OracleQuery1.Field('DEALER');
      end;
      show();
      self.Repaint;
      tmr_CloseForm.Enabled := true;
    end;
  end;
end;

procedure TFrmPrintTicket.tmr_CloseFormTimer(Sender: TObject);
begin
  tmr_CloseForm.Enabled := false;
  Close();
end;

end.
